-
Notifications
You must be signed in to change notification settings - Fork 536
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prevents body scroll when Dialog is open #3547
Conversation
🦋 Changeset detectedLatest commit: 85b0390 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
I'm not sure if this solution is SSR-compatible or not. I tried doing this with CSS using |
One caveat: this probably won't work on any scrollable elements within the body. |
size-limit report 📦
|
src/Dialog/Dialog.tsx
Outdated
document.body.style.overflow = 'hidden' | ||
|
||
return () => { | ||
document.body.style.overflow = '' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not blocking: should we keep a track of what it was set to before and reset to that, just in case it was scroll or clip instead of the default visible?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I'll update it.
Sets
body
tooverflow: hidden
when a Dialog is mounted.Closes https://github.com/github/primer/issues/2354
How to test:
Add this line to a story:
Merge checklist
Take a look at the What we look for in reviews section of the contributing guidelines for more information on how we review PRs.